package com.wuyou.dataStructure.tree;

/**
 * 是否对称二叉树
 */
public class IsSymmetric {

    public static void main(String[] args) {
        IsSymmetric main = new IsSymmetric();
        TreeNode root = new TreeNode(1);
        TreeNode root2 = new TreeNode(2);
        TreeNode root3 = new TreeNode(2);
        TreeNode root4 = new TreeNode(3);
        TreeNode root5 = new TreeNode(4);
        TreeNode root6 = new TreeNode(4);
        TreeNode root7 = new TreeNode(3);
        root.left=root2;
        root.right=root3;
        root.left.left=root4;
        root.left.right=root5;
        root.right.left = root6;
        root.right.right = root7;
        System.out.println(main.sol_1(root));
    }


    public boolean sol_1(TreeNode root){
        return isMirror(root.left, root.right);
    }
    public boolean isMirror(TreeNode t1, TreeNode t2) {
        if (t1 == null && t2 == null) return true;
        if (t1 == null || t2 == null) return false;
        return (t1.val == t2.val)
                && isMirror(t1.left, t2.right)
                && isMirror(t1.right, t2.left);
    }
}
